﻿namespace ReplayDataFile
{
    using System;
    using System.Runtime.CompilerServices;

    [Serializable]
    public class TimeSegment
    {
        public TimeSegment Clone()
        {
            return new TimeSegment { BeginTime = this.BeginTime, BeginRecordNo = this.BeginRecordNo, EndTime = this.EndTime, EndRecordNo = this.EndRecordNo };
        }

        public override string ToString()
        {
            return string.Format("{0}({1}) - {2}({3}) Length:{4} RecordCount:{5}", new object[] { this.BeginTime, this.BeginRecordNo, this.EndTime, this.EndRecordNo, this.Length, this.EndRecordNo - this.BeginRecordNo });
        }

        public long BeginRecordNo { get; set; }

        public DateTime BeginTime { get; set; }

        public long EndRecordNo { get; set; }

        public DateTime EndTime { get; set; }

        public TimeSpan Length
        {
            get
            {
                if (this.EndTime == DateTime.MinValue)
                {
                    return new TimeSpan(0L);
                }
                TimeSpan span = (TimeSpan) (this.EndTime - this.BeginTime);
                if (span.Ticks < 0L)
                {
                    return new TimeSpan(-span.Ticks);
                }
                return span;
            }
        }
    }
}

